/**
 * Created by jn-dinggao on 2017/7/20.
 */
app.factory('InfoAuthService',  function($http, $q, $resource, $cookieStore, serviceUtil, ACTIONS, METHODS, URL){
    var factory = {};
    var param = {};
    var authUrl = URL.BASEURL + URL.AUTHURL;

    var initParam = function(){
        param = {};
    };

    factory.get = function(id) {
        initParam();
        return serviceUtil.excute(authUrl +'get/' + id, param, METHODS.get);
    };

    factory.getAuthList = function (page,queryParam) {
        initParam();
        param = {};
        if(page){
            param.pageNo = page.pageNo;
            param.pageSize = page.pageSize;
        }
        if(queryParam){
            param.name = queryParam.name;
        }
        return serviceUtil.excute(authUrl +'getList', param, METHODS.getList);
    };

    factory.getAuthListForZtree = function () {
        return serviceUtil.excute(authUrl + "getListForZtree",null,METHODS.getList)
    };

    factory.findParentElement = function (type) {
        return serviceUtil.excute(authUrl + "findParentElement/"+type,null,METHODS.getList)
    };

    factory.findRoleAuthByRoleId = function(roleId) {
        initParam();
        param = {};
        return serviceUtil.excute(authUrl +'findRoleAuthByRoleId/'+roleId, param, METHODS.getList);
    };

    factory.delete = function(id) {
        initParam();
        return serviceUtil.excute(authUrl +'delete/' + id, param ,METHODS.delete);
    };



    factory.addAuth = function(auth) {
        initParam();
        param.id = auth.id;
        param.parentId = auth.parentId;
        param.authName = auth.authName;
        param.authCode = auth.authCode;
        param.remark = auth.remark;
        param.authUrl = auth.authUrl;
        param.authType = auth.authType;
        return serviceUtil.excute(authUrl +'add', param ,METHODS.save);
    };

    return factory;
});